// 统一响应格式中间件
const responseFormatter = (req, res, next) => {
  // 成功响应
  res.success = (data, message = '操作成功') => {
    return res.status(200).json({
      success: true,
      message,
      data
    });
  };

  // 创建成功响应
  res.created = (data, message = '创建成功') => {
    return res.status(201).json({
      success: true,
      message,
      data
    });
  };

  // 错误响应
  res.error = (message = '操作失败', statusCode = 400, errors = null) => {
    return res.status(statusCode).json({
      success: false,
      message,
      errors: errors || undefined
    });
  };

  next();
};

module.exports = responseFormatter;